package com.yanqu.road.server.manger.activity.yuanbaolottery;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.yuanbaolottery.YuanBaoLotteryModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class YuanBaoLotteryMgr extends TempMgr {
    private static YuanBaoLotteryActivityConfig config = null;
    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static void reloadActivity() {
        getLogger().info("reload YuanBaoLottery activity start");
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.YuanBaoLottery.getValue());
        if (openActivityInfoList.isEmpty()) {
            getLogger().info("no YuanBaoLottery Activity in show time");
            config = null;
        } else {
            ActivityInfo tempActivityInfo = openActivityInfoList.get(0);
            List<Integer> activityIdList = new ArrayList<>();
            int activityId = tempActivityInfo.getActivityId();
            activityIdList.add(activityId);
            Map<String, ActivityConfig> activityConfigMap = ActivityMgr.getActivityConfigMap(activityId);
            YuanBaoLotteryActivityConfig tempConfig = new YuanBaoLotteryActivityConfig(tempActivityInfo, activityConfigMap);

            config = tempConfig;
        }

        for (GamePlayer player : GamePlayerMgr.getAllOnlinePlayer()) {
            player.getModule(YuanBaoLotteryModule.class).initSystemOpen();
        }

        getLogger().info("reload YuanBaoLottery activity end");
    }

    public static YuanBaoLotteryActivityConfig getConfig() {
        return config;
    }
}
